package com.ews.onlineexchange.model;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Formula;
import org.hibernate.validator.constraints.Length;

@Entity
public class TradeRating extends DataEntity {
	
	/**
	 * 
	 */
	private static final long		serialVersionUID	= 1L;

	private Trade					trade;
	private String					rateText;					// 填写的评价

	private Integer					score				= 5;
	private Date					ratingDate;
	private String					quality;					// 服务质量
	private String					effectiveness;				// 服务时效
	private String					attitude;					// 服务态度
	private String					charge;						// 服务收费
	private String					standard;					// 服务标准

	private AdditionalTradeRating	additionalTradeRating;
	
	@OneToOne
	@NotNull
	@JoinColumn(unique = true)
	public Trade getTrade() {
		return trade;
	}

	public void setTrade(Trade trade) {
		this.trade = trade;
	}

	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getRatingDate() {
		return ratingDate;
	}

	public void setRatingDate(Date ratingDate) {
		this.ratingDate = ratingDate;
	}


	public String getRateText() {
		return rateText;
	}

	public void setRateText(String rateText) {
		this.rateText = rateText;
	}
	
	@Length(max = 4000)
	public String getQuality() {
		return quality;
	}

	public void setQuality(String quality) {
		this.quality = quality;
	}
	
	@Length(max = 4000)
	public String getEffectiveness() {
		return effectiveness;
	}

	public void setEffectiveness(String effectiveness) {
		this.effectiveness = effectiveness;
	}
	
	@Length(max = 4000)
	public String getAttitude() {
		return attitude;
	}

	public void setAttitude(String attitude) {
		this.attitude = attitude;
	}
	
	@Length(max = 4000)
	public String getCharge() {
		return charge;
	}

	public void setCharge(String charge) {
		this.charge = charge;
	}
	
	@Length(max = 4000)
	public String getStandard() {
		return standard;
	}

	public void setStandard(String standard) {
		this.standard = standard;
	}

	@NotNull
	@Min(value = 0)
	@Max(value = 10)
	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	@OneToOne( mappedBy = "tradeRating" )
	public AdditionalTradeRating getAdditionalTradeRating() {
		return additionalTradeRating;
	}

	public void setAdditionalTradeRating( AdditionalTradeRating additionalTradeRating ) {
		this.additionalTradeRating = additionalTradeRating;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((rateText == null) ? 0 : rateText.hashCode());
		result = prime * result + ((score == null) ? 0 : score.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		TradeRating other = (TradeRating) obj;
		if (rateText == null) {
			if (other.rateText != null)
				return false;
		} else if (!rateText.equals(other.rateText))
			return false;
		if (score == null) {
			if (other.score != null)
				return false;
		} else if (!score.equals(other.score))
			return false;
		return true;
	}

	
	
}
